<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
function route_class($str = '')
{
    $names = [
        request()->controller(true),
        request()->action(true),
        'page'
    ];
    return implode('-', $names);
}

/**
 * 上传单张图片--返回的是Upload Image Path
 * @Author   zhanghong
 * @DateTime 2019-02-18
 * @param    string     $backcall 回调字段名
 * @param    integer    $width    图片高度
 * @param    integer    $height   图片宽度
 * @param    string     $image    当前图片路径
 * @param    string     $backcall_name    回调字段ID
 * @param    string     $upload_type    上传文件类型
 */
function create_upload_image($backcall="image", $width=100, $height=100, $image="", $backcall_name="", $upload_type = 'image')
{
    if(empty($backcall_name)){
      $backcall_name = $backcall;
    }
    echo '<iframe scrolling="no" frameborder="0" border="0" onload="this.height=this.contentWindow.document.body.scrollHeight;this.width=this.contentWindow.document.body.scrollWidth;" width='.$width.' height="'.$height.'"  src="'.url('upload/create').'?width='.$width.'&height='.$height.'&backcall='.$backcall.'&image='.$image.'&backcall_name='.$backcall_name.'&upload_type='.$upload_type.'"></iframe>
         <input type="hidden" name="'.$backcall_name.'" id="'.$backcall.'">';
}

/**
 * 顶部导航是否选中样式
 * @Author   zhanghong(Laifuzi)
 * @DateTime 2019-02-23
 * @param    string             $ctr_name 判断控制器名称
 * @param    string             $act_name 判断方法名称
 * @param    array              $param    附加参数
 * @return   string                       [description]
 */
function navbar_class($ctr_name, $act_name, $param = [])
{
    $request = request();
    $ctr_request = $request->controller(true);
    $act_request = $request->action(true);

    if($ctr_name != $ctr_request || $act_name != $act_request){
        return '';
    }

    if(empty($param)){
        return 'active';
    }

    $is_active = true;
    foreach ($param as $name => $value) {
        $param_value = $request->param($name);
        $pm[$name] = $param_value;
        if($param_value != $value){
            $is_active = false;
            break;
        }
    }

    if($is_active){
        return 'active';
    }else{
        return '';
    }
}

/**
 * 排序方式导航是否active样式名
 * @Author   zhanghong(Laifuzi)
 * @DateTime 2019-02-25
 * @param    string             $name     判断参数名
 * @param    string             $value    判断参数值
 * @param    boolean            $is_equal 判断方式
 * @return   string                       [description]
 */
function order_active($name, $value, $is_equal = true)
{
    $param_value = request()->get($name);
    $is_active = false;
    if($is_equal == true && $param_value == $value){
        $is_active = true;
    }else if($is_equal != true && $param_value != $value){
        $is_active = true;
    }

    if($is_active){
        return 'active';
    }else{
        return '';
    }
}